<template>

    <div>

        <!--弹窗页面部分-->
        <div class="management-modal-win" v-show="modelShow">
            <!-- 标题 -->
            <el-row>
                <el-col :span="24">
                    <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt="" class="lf modal-img">
                    <div class="lf modal-title">{{modalTitle}}</div>
                    <div class="rf close" @click="closeModual()">X</div>
                </el-col>
            </el-row>


            <el-row>
                <el-col :span="24">
                    <div class="msg-win">
                        <!-- 修改弹窗 -->
                        <div>
                            <el-row class="sale-container">
                                <el-col :span="24">
                                    <!--<FormData :ob="saleTicket" :op="saleTicOption" class="sale-form"></FormData>-->

                                    <el-form :inline="true" :model="formInline" class="demo-form-inline">

                                        <el-form-item label="机构编码">
                                            <el-input v-model="formInline.org_code"></el-input>
                                        </el-form-item>

                                        <el-form-item label="机构简称">
                                            <el-input v-model="formInline.org_name"></el-input>
                                        </el-form-item>

                                        <el-form-item label="机构全称">
                                            <el-input v-model="formInline.org_name_full"></el-input>
                                        </el-form-item>

                                        <el-form-item label="联系人">
                                            <el-input v-model="formInline.contacts"></el-input>
                                        </el-form-item>

                                        <el-form-item label="联系电话">
                                            <el-input v-model="formInline.contacts_phone"></el-input>
                                        </el-form-item>

                                        <el-form-item label="信用级别">
                                            <el-select v-model="formInline.credit_level_id">
                                                <el-option v-for="(item,index) in credit_level_List"
                                                           :key="index"
                                                           :label="item.name"
                                                           :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>

                                        <el-form-item label="信用额度">
                                            <el-input v-model="formInline.credit_limit"></el-input>
                                        </el-form-item>

                                        <el-form-item label="保证金">
                                            <el-input v-model="formInline.deposit"></el-input>
                                        </el-form-item>
                                        <el-form-item label="备注" size="medium "  >
                                            <el-input v-model="formInline.remark"  ></el-input>
                                        </el-form-item>
                                    </el-form>


                                </el-col>
                            </el-row>
                            <el-row class="sale-container">
                                <el-col :span="24">
                                    <!--<FormData :ob="saleTicketII" :op="saleTicOptionII"></FormData>-->
                                    <!--<button class="check-btn rf" @click="closeSaleWin"><img-->
                                    <!--src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt=""-->
                                    <!--class="btn-img">取消-->
                                    <!--</button>-->
                                    <!--<button class="check-btn rf" @click="sendSale"><img-->
                                    <!--src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt=""-->
                                    <!--class="btn-img">提交-->
                                    <!--</button>-->
                                    <div class="container">
                                        <el-row>
                                            <el-col :span="24" class="table-fun1">
                                                <img src="../../assets/imgs/operation_icon_xiugai_default.png" alt=""
                                                     class="lf">
                                                <div class="lf choose-title2 fun-text">档案管理</div>
                                                <img src="../../assets/imgs/operation_icon_shuaxin_default.png" alt=""
                                                     class="lf">
                                                <div class="lf choose-title2 fun-text" @click="refresh">刷新</div>
                                                <img src="../../assets/imgs/operation_icon_tianjia_default.png" alt=""
                                                     class="lf">
                                                <div class="lf choose-title2 fun-text" @click="add">添加</div>
                                                <img src="../../assets/imgs/operation_icon_shanchu_default.png" alt=""
                                                     class="lf">
                                                <div class="lf choose-title2 fun-text" @click="del">删除</div>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <TableData :data="customList[0].data" :option="customList[0].option"
                                                           :rowChange="rowChange"></TableData>
                                            </el-col>
                                        </el-row>
                                    </div>
                                </el-col>
                            </el-row>

                        </div>
                    </div>


                </el-col>
            </el-row>

            <el-row>
                <el-col :span="24">
                    <button class="check-btn rf" @click="closemanagementWin"><img
                            src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt=""
                            class="btn-img">取消
                    </button>
                    <button class="check-btn rf" @click="sendmanagement"><img
                            src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt=""
                            class="btn-img">确定
                    </button>
                </el-col>
            </el-row>

        </div>

        <!--表格数据-->
        <el-container style="height: 800px; border: 1px solid #eee">
            <el-container>
                <el-main>
                    <el-table :data="tableData" @row-dblclick="rowDbclickHandle">
                        <el-table-column prop="no" label="机构编号" width="140">
                        </el-table-column>
                        <el-table-column prop="name" label="机构简称" width="120">
                        </el-table-column>
                        <el-table-column prop="jigoutype" label="机构类型">
                        </el-table-column>
                        <el-table-column prop="deposit" label="保证金">
                        </el-table-column>
                        <el-table-column prop="credit_level" label="信用级别" width="140">
                        </el-table-column>
                        <el-table-column prop="credit_limit" label="额度" width="120">
                        </el-table-column>
                        <el-table-column prop="contacts" label="联系人">
                        </el-table-column>
                        <el-table-column prop="contacts_phone" label="联系电话">
                        </el-table-column>
                        <el-table-column prop="create" label="操作">
                            <template slot-scope="scope">
                                <el-button
                                        @click="toalter(scope.row)"
                                        type="text"
                                        size="small">
                                    编辑
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-main>
            </el-container>
        </el-container>





    </div>

</template>

<script>
    import qs from "qs";

    // const DIC = {
    //     station: [],
    //     managemrntlist: [],
    // };

    export default {

        data() {

            return {


                formInline: {
                    id: "",
                    org_code: "",
                    org_name: "",
                    org_name_full: "",
                    contacts: "",
                    contacts_phone: "",
                    credit_level_id: '',
                    credit_limit: "",
                    deposit: "",
                    remark: "",
                },

                credit_level_List: [],

                currentRow: "",

                activeTag: "3-3",

                tableData: [],
                modelShow: false,
                modalTitle: "",


                // saleTicket: {},
                // saleTicOption: {
                //     dicData: [],
                //     column: [
                //         {
                //             label: "",
                //             prop: "id",
                //             visdiplay: false
                //
                //         },
                //         {
                //             label: "机构编码",
                //             prop: "org_code",
                //             valueDefault: "",
                //             span: 6,
                //
                //         },
                //         {
                //             label: "机构简称",
                //             prop: "org_name",
                //             valueDefault: "",
                //             span: 6
                //         },
                //         {
                //             label: "机构全称",
                //             prop: "org_name_full",
                //             valueDefault: "",
                //             span: 8
                //         },
                //         {
                //             label: "联系人",
                //             prop: "contacts",
                //             valueDefault: "",
                //             span: 6
                //         },
                //         {
                //             label: "联系电话",
                //             prop: "contacts_phone",
                //             valueDefault: "",
                //             span: 8
                //         },
                //         {
                //             label: "信用级别",
                //             type: "select",
                //             prop: "credit_limit",
                //             valueDefault: "",
                //             data: "",
                //             span: 6
                //         },
                //         {
                //             label: "信用额度",
                //             prop: "credit_limit",
                //             valueDefault: "",
                //             data: "",
                //             span: 6
                //         },
                //         {
                //             label: "保证金",
                //             prop: "deposit",
                //             valueDefault: "",
                //             span: 6
                //         },
                //         {
                //             label: "备注",
                //             prop: "remark",
                //             valueDefault: "1",
                //             span: 15
                //         }
                //     ]
                // },




                customList: [
                    {
                        page: {
                            pageSizes: [10, 20, 30, 40],
                            total: 2,
                            currentPage: 1,
                            pageSize: 10
                        },
                        data: [],
                        option: {
                            page: true,
                            stripe: true,
                            menu: false,
                            align: "center",
                            menuAlign: "center",
                            column: []
                        }
                    }
                ],

            }
        },

        methods: {



            rowDbclickHandle(row, event) {
                console.log('000')
                console.log(row)
                console.log(event)
                this.modelShow = true;
                this.modalTitle = "修改";
                this.getmanagementinfo(row.id);
            },

            toalter(row) {
                console.log(row);
                this.modelShow = true;
                this.modalTitle = "修改";
                this.getmanagementinfo(row.id);

            },

            //获取信用级别数据信息
            getCredisLevels() {
                var arr = [];
                this.$http.post(
                    "/distribution/base/creditLevel/getCredisLevels"
                )
                    .then(data => {
                        this.credit_level_List = data.data;
                    })

            },


            //获取弹窗补全信息
            getmanagementinfo(id) {
                this.formInline = {
                    org_code: "",
                    org_name: "",
                    org_name_full: "",
                    contacts: "",
                    contacts_phone: "",
                    credit_level_id:"",
                    credit_limit: "",
                    deposit: "",
                    remark: "",
                }
                this.$http
                    .get("/distribution/org/get?id=" + id
                    )
                    .then(data => {
                        console.log(data.data);
                        //     console.log(item);
                        this.formInline.id = data.data[1].id,
                            this.formInline.org_code = data.data[1].org_code,
                            this.formInline.org_name = data.data[1].org_name,
                            this.formInline.org_name_full = data.data[1].org_name_full,
                            this.formInline.contacts = data.data[1].contacts,
                            this.formInline.contacts_phone = data.data[1].contacts_phone,
                            this.formInline.credit_limit = data.data[1].credit_limit,
                            this.formInline.deposit = data.data[1].deposit,
                            this.formInline.remark = data.data[1].remark || ''


                        // console.log(this.formInline.org_name);


                    });

            },
            closeModual() {
                this.modelShow = false;
            },
            rowChange(val) {
                this.currentRow = val.id
            },


            closemanagementWin() {
                this.modelShow = false;
            },
            //保存修改
            sendmanagement() {
                var params = "distributionOrg.id=" + this.formInline.id +
                    "&distributionOrg.contacts=" + this.formInline.contacts + "&" +
                    "distributionOrg.contacts_phone=" + this.formInline.contacts_phone +
                    "&distributionOrg.credit_level_id=" + this.formInline.credit_level_id + ""+
                    "&distributionOrg.credit_limit=" + this.formInline.credit_limit + "&" +
                    "distributionOrg.deposit=" + this.formInline.deposit +
                    "&distributionOrg.remark=" + this.formInline.remark + "" ;
                this.$http
                    .get("/distribution/org/update?" +
                        "distributionOrg.id=" + this.formInline.id +
                        "&distributionOrg.contacts=" + this.formInline.contacts + "&" +
                        "distributionOrg.contacts_phone=" + this.formInline.contacts_phone +
                        "&distributionOrg.credit_level_id=" + this.formInline.credit_level_id + ""+
                        "&distributionOrg.credit_limit=" + this.formInline.credit_limit + "&" +
                        "distributionOrg.deposit=" + this.formInline.deposit +
                        "&distributionOrg.remark=" + this.formInline.remark + "",
                        qs.stringify({
                            'distributionOrg.id': this.formInline.id,
                            'distributionOrg.contacts': this.formInline.contacts,
                            'distributionOrg.contacts_phone': this.formInline.contacts_phone,
                            'distributionOrg.credit_level_id': this.formInline.credit_level_id,
                            'distributionOrg.credit_limit': this.formInline.credit_limit,
                            'distributionOrg.deposit': this.formInline.deposit,
                            'distributionOrg.remark': this.formInline.remark
                        })
                    )
                    .then(data => {
                        if (data.data[0] == 0) {
                            this.$message({
                                message: data.data[1],
                                type: "success"
                            });
                            this.closemanagementWin();
                            this.managemrntlist();
                        } else {
                            this.$message.error(data.data[1]);
                        }
                    });
            },

            refresh() {
                this.customList[0].data = [];
                this.$http
                    .post("")
                    .then(data => {
                        console.log(data);
                        for (var item of data.data.list) {
                            this.customList[0].data.push({
                                title: item.title,
                                formula: item.formula,
                                remarks: item.remarks
                            });
                        }
                    });
            },
            add() {
                this.$http
                    .get(""
                    )
                    .then(data => {
                        if (data.data[0] == 0) {
                            this.$message({
                                message: data.data[1],
                                type: "success"
                            });
                            this.refresh();
                        } else {
                            this.$message.error(data.data[1]);
                        }
                    });
            },
            del() {
                this.$http.post(""
                ).then((data) => {
                    if (data.data[0] == 0) {
                        this.$message({
                            message: data.data[1],
                            type: "success"
                        })
                        this.refresh();
                    } else {
                        this.$message.error(data.data[1]);
                    }
                });
            },


            tableCreate() {
                this.customList[0].option.column.push(
                    {
                        label: "文档名称",
                        prop: "title",
                        span: 6,
                    },
                    {
                        label: "文档类型",
                        prop: "formula",
                        span: 6,
                    },
                    {
                        label: "文档大小",
                        prop: "remarks",
                        span: 6,
                    },
                );
            },

            //自动加载机构列表数据
            managemrntlist() {
                var arr = this.tableData = [];


                this.$http
                    .post("/distribution/org/list"
                    )
                    .then(res => {

                        for (var c of res.data.list)
                            arr.push({
                                id: c.id,
                                no: c.no,
                                name: c.name,
                                jigoutype: c.jigoutype,
                                deposit: c.deposit,
                                credit_level: c.credit_level,
                                credit_limit: c.credit_limit,
                                contacts: c.contacts,
                                contacts_phone: c.contacts_phone,

                            });

                    });

            },

        },
        mounted() {
            console.log("custom");
            this.tableCreate();
            // this.refresh();
            this.$emit("sendActive", this.activeTag);
            this.getCredisLevels();
            this.managemrntlist();
        }
    }

</script>
<style scoped src="../../assets/css/sell/sell.css"></style>
<style scoped>
    .table-fun1 {
        height: 80px;
        padding-left: 10px;
    }

    .management-modal-win {
        width: 1000px;
        height: 530px;
        position: absolute;
        border-radius: 5px;
        border: 1px solid #E4F0EF;
        border-top: 5px solid #00786D;
        top: 100px;
        left: 50%;
        margin-left: -500px;
        background: white;
        z-index: 99;
        padding: 20px;
        box-shadow: 0 0 1px 1px #C2C7D0;
    }

</style>